package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.pojo.Competitions.CompetitionScore;
import com.example.demo.pojo.Competitions.CompetitionScoreDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface CompetitionScoreMapper extends BaseMapper<CompetitionScore> {

    @Select("SELECT cs.id, cs.competition_id, cs.user_competition_id, cs.score, cs.rank, u.real_name " +
            "FROM competition_scores cs " +
            "JOIN user u ON cs.user_competition_id = u.id " +
            "WHERE cs.user_competition_id = #{userId} AND cs.competition_id = #{competition_id}")
    CompetitionScoreDTO selectCompetitionScoreByUserIdAndScoreId(@Param("userId") Integer userId, @Param("competition_id") Integer competition_id);

    @Select("SELECT cs.id, cs.competition_id, cs.user_competition_id, cs.score, cs.rank, u.real_name " +
            "FROM competition_scores cs " +
            "JOIN user u ON cs.user_competition_id = u.id " +
            "WHERE cs.competition_id = #{competition_id} " +
            "ORDER BY cs.score DESC")
    List<CompetitionScoreDTO> selectCompetitionScoresList(@Param("competition_id") Integer competition_id);
}
